package 传智播客_黑马.java高级.网络编程;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

class B {
    public B() throws IOException {
        String str = null;
        //建立连接
        ServerSocket serverSocket = new ServerSocket(6000);
        Socket socket = serverSocket.accept();

        System.out.println("连接成功！！！");

        //接收数据
        InputStream inputStream = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int len;
//        int len = inputStream.read(bytes);
////        String str = new String(bytes,0,len);
////        System.out.println(str);

        while ((len = inputStream.read(bytes))!=-1){
            str = new String(bytes,0,len);
            System.out.println(str);
        }


        //关闭流、socket
        inputStream.close();
        socket.close();
    }

    public static void main(String[] args) throws IOException {
        new B();
    }
}
